package com.gitee.srurl.system.util;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gitee.srurl.system.util.response.PageResponse;
import com.gitee.srurl.system.util.response.R;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

/**
 * @author zxw
 * @date 2022/12/1
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public abstract class PageUtil {

    public static <T> PageResponse<T> mybatisPageTransfer(IPage<T> page) {

        PageResponse<T> pageResponse = new PageResponse<>();

        pageResponse.setRecords(page.getRecords());
        pageResponse.setTotal(page.getTotal());
        pageResponse.setCurrentPage(page.getCurrent());
        pageResponse.setPageSize(page.getSize());

        return pageResponse;
    }

    public static <T> R<PageResponse<T>> responsePage(IPage<T> page) {

        PageResponse<T> pageResponse = mybatisPageTransfer(page);
        return R.page(pageResponse);
    }
}
